﻿using UnityEngine;
using UnityEngine.SceneManagement;

class MonsterMgr
{
    //怪物集合
    public MonsterCollection monsterList = new MonsterCollection();

    //创建怪物
    public Monster CreateMonster(EnumMonster monsterType)
    {
        
        Monster monster = Game.Instance.monsterFactory.Get(monsterType);
        Scene scene = Game.Instance.scene;
        if (scene.isLoaded)
            SceneManager.MoveGameObjectToScene(monster.gameObject, scene);
        monsterList.Add(monster);
        return monster;
    }

    public void DeleteMonster(int id)
    {
        if (!IsContainMonster(id))
            return;
    }

    public Monster GetNearMosnter()
    {
        return monsterList.GetNearMonster();
    }


    public Monster GetMonsterById(int id)
    {
        return monsterList.GetMonsterById(id);
    }

    public bool IsContainMonster(int id)
    {
        return monsterList.IsContain(id);
    }

    public void MonsterDie(Transform transform)
    {
        Debug.Log("MonsterDie");
        GameObject hp = (GameObject)Resources.Load("Prefabs/Item/Bottle_Health");
        GameObject obj = GameObject.Instantiate(hp);
        obj.transform.position = transform.position;
    }

    //====================================
    private static MonsterMgr instance;

    public static MonsterMgr Instance
    {
        get
        {
            if (instance == null)
            {
                instance = new MonsterMgr();
            }
            return instance;
        }
    }
}
